package com.twu.biblioteca;

import com.twu.biblioteca.dao.MemoryBookDao;
import com.twu.biblioteca.dao.MemoryMovieDao;
import com.twu.biblioteca.dao.MemoryUserDao;
import com.twu.biblioteca.render.ConsoleRender;
import com.twu.biblioteca.service.ActuatorBuilder;
import com.twu.biblioteca.service.BookService;
import com.twu.biblioteca.service.MovieService;
import com.twu.biblioteca.service.UserService;
import com.twu.biblioteca.ui.IAvailableChecker;
import com.twu.biblioteca.ui.Menu;
import com.twu.biblioteca.ui.MenuItem;
import com.twu.biblioteca.ui.Shell;

import java.util.Scanner;

public class BibliotecaApp {


    public static void main(String[] args) {
        final BookService bookService = new BookService();
        bookService.setBookDao(new MemoryBookDao());

        final MovieService movieService = new MovieService();
        movieService.setMovieDao(new MemoryMovieDao());

        final UserService userService = new UserService();
        userService.setUserDao(new MemoryUserDao());

        Scanner sc = new Scanner(System.in);
        IRender consoleRender = new ConsoleRender();

        IAvailableChecker loginChecker = new IAvailableChecker() {
            @Override
            public boolean isAvailable() {
                return userService.isLogined();
            }
        };

        ActuatorBuilder builder = new ActuatorBuilder(bookService, movieService, userService, sc, consoleRender);

        Menu menu = new Menu();
        menu.addItem(new MenuItem("List Books", builder.buildListBooksActuator()));
        menu.addItem(new MenuItem("CheckOut Book", builder.buildBookCheckOutActuator(), loginChecker));
        menu.addItem(new MenuItem("Return Book", builder.buildBookReturnActuator(), loginChecker));
        menu.addItem(new MenuItem("List Movies", builder.buildListMoviesActuator()));
        menu.addItem(new MenuItem("CheckOut Movie", builder.buildMovieCheckOutActuator()));
        menu.addItem(new MenuItem("Login", builder.buildUserLoginActuator()));
        menu.addItem(new MenuItem("User information", builder.buildUserInformationActuator(), loginChecker));
        menu.addItem(new MenuItem("Quit", builder.buildQuitActuator()));

        new Shell(menu, sc, consoleRender).run();
    }
}
